//package com.anji.captcha.controller;
//
//
//import com.anji.captcha.model.common.ResponseModel;
//import com.anji.captcha.model.vo.CaptchaVO;
//import com.anji.captcha.service.CaptchaCacheService;
//import com.anji.captcha.service.CaptchaService;
//import com.anji.captcha.util.ImageUtils;
//import com.anji.captcha.util.StringUtils;
//
//import com.neu.base.Result;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.beans.factory.annotation.Qualifier;
//import org.springframework.web.bind.annotation.PostMapping;
//import org.springframework.web.bind.annotation.RequestBody;
//import org.springframework.web.bind.annotation.RequestMapping;
//import org.springframework.web.bind.annotation.RestController;
//
//
//import javax.annotation.PostConstruct;
//import javax.annotation.Resource;
//import javax.servlet.http.HttpServletRequest;
//import java.util.ServiceLoader;
//
//@Slf4j
//@RestController
//@RequestMapping("/captcha")
//public class CaptchaController {
//    @Autowired
//    private CaptchaCacheService captchaService;
//    @PostConstruct
//    public void logCaptchaService() {
//        log.info("CaptchaController注入的 CaptchaService: {}", captchaService.getClass().getName());
//        ServiceLoader<CaptchaCacheService> loader = ServiceLoader.load(CaptchaCacheService.class);
//        for (CaptchaCacheService service : loader) {
//            log.info("CaptchaCacheService 的实现类: {}", service.getClass().getName());
//        }
//
//    }
//
//
//    @PostMapping("/get") // 获取图片
//    public ResponseModel get(@RequestBody CaptchaVO data, HttpServletRequest request) {
//        assert request.getRemoteHost()!=null;
//        //data.setBrowserInfo(getRemoteId(request));
//        ResponseModel responseModel = captchaService.get(data);
//        log.info("2222 {}", responseModel);
//        return responseModel;
//    }
//
//    @PostMapping("/check") // 进行校验
//    public ResponseModel check(@RequestBody CaptchaVO data, HttpServletRequest request) {
//        data.setBrowserInfo(getRemoteId(request));
//        ResponseModel check = captchaService.check(data);
//        return check;
//    }
//
//    @PostMapping("/verify") // 二次校验
//    public ResponseModel verify(@RequestBody CaptchaVO data, HttpServletRequest request) {
//        return captchaService.verification(data);
//    }
//
//    public static final String getRemoteId(HttpServletRequest request) {
//        String xfwd = request.getHeader("X-Forwarded-For");
//        String ip = getRemoteIpFromXfwd(xfwd);
//        String ua = request.getHeader("user-agent");
//        if (StringUtils.isNotBlank(ip)) {
//            return ip + ua;
//        }
//        return request.getRemoteAddr() + ua;
//    }
//
//    private static String getRemoteIpFromXfwd(String xfwd) {
//        if (StringUtils.isNotBlank(xfwd)) {
//            String[] ipList = xfwd.split(",");
//            return StringUtils.trim(ipList[0]);
//        }
//        return null;
//    }
//}
